﻿using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Canteen.Core.Common
{
    public interface IRedisCacheManager
    {
        TEntity RedisCache<TEntity>(Func<IDatabase, TEntity> func, int dbNum);
        TEntity RedisCache<TEntity>(Func<IDatabase, TEntity> func);

        //获取值
        Task<string> GetAsync(string key, int dbNum = 0);
        //获取值并序列化
        Task<TEntity> GetAsync<TEntity>(string key, int dbNum = 0);

        //添加
        Task<bool> SetAsync(string key, string value, TimeSpan expiry, int dbNum = 0);
        //添加
        Task<bool> SetAsync<TEntity>(string key, TEntity value, TimeSpan expiry, int dbNum = 0);

        //判断是否存在
        Task<bool> ExistsAsync(string key, int dbNum = 0);
        //移除某一个缓存值
        Task<bool> DeleteAsync(string key, int dbNum = 0);
        //全部清除
        Task ClearAll();


        //辅助方法-转换
        string ConvertJson<TEntity>(TEntity value);
        TEntity ConvertObj<TEntity>(RedisValue value);
        List<TEntity> ConvetList<TEntity>(RedisValue[] values);
        RedisKey[] ConvertRedisKeys(List<string> redisKeys);
    }
}